package com.tbit.uqbike.service.eventListener;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.tbit.uqbike.object.event.ParkPointDeleteEvent;
import com.tbit.uqbike.service.business.ParkMachineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 站点事件监听器
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2024-8-16
 */
@Slf4j
@Component
public class ParkPointEventListener {

    @Resource
    private ParkMachineService parkMachineService;

    @EventListener
    public void  onParkPointDelete(ParkPointDeleteEvent event) {
        log.info("ParkPointEventListener.onParkPointDelete {}", JSON.toJSONString(event));
        List<Integer> parkPointIds = event.getParkPointIds();
        if (CollectionUtil.isNotEmpty(parkPointIds)) {
            parkMachineService.deleteByParkPointIds(parkPointIds);
        }

    }
}
